import { Button, StyleSheet, View, Text } from 'react-native';
import React, { useState } from 'react';
import { RNCamera } from 'react-native-camera';
import { TestSuite, TestCase, Tester } from '@rnoh/testerino';

export function getCameraIdAsyncTest() {
  const [cameraIdResultText, setcameraIdResultText] = React.useState<string>("");
  const getCameraIdsAsync = () => {
    this.camera.getCameraIdsAsync().then((data)=>{
      for (let i = 0; i < data.length; i++) {
        setcameraIdResultText(JSON.stringify(data))
      }
    })
  };


  return (
    <Tester>
      <TestSuite name="getCameraIdsAsync">
        <TestCase itShould={`getCameraIdsAsync`}>
        <Text>result：{cameraIdResultText}</Text>
          <RNCamera
            ref={ref => {
              this.camera = ref;
            }}
            style={style.cameraPreview}
          >
          </RNCamera>
          {/* 按钮组 */}
          <View style={style.actionBtn}>
            <Button title="getCameraIdsAsync" onPress={getCameraIdsAsync}></Button>
          </View>
        </TestCase>
      </TestSuite>
    </Tester >
  );
}

const style = StyleSheet.create({
  cameraPreview: { width: '100%', aspectRatio: 56 / 100 },
  actionBtn: {
    flexDirection: 'row',
    flexWrap: 'wrap',
    justifyContent: 'space-evenly',
    padding: 10,
    gap: 5,
    position: 'absolute',
    top: 300,
  },
  text: {
    fontSize: 20,
    textAlign: 'center',
    color: '#000',
  },
  flipText: {
    color: 'white',
    fontSize: 15,
  },
  flipButton: {
    flex: 0.3,
    height: 40,
    marginHorizontal: 2,
    marginBottom: 10,
    marginTop: 10,
    borderRadius: 8,
    borderColor: 'white',
    borderWidth: 1,
    padding: 5,
    alignItems: 'center',
    justifyContent: 'center',
  },
  zoomText: {
    position: 'absolute',
    bottom: 70,
    zIndex: 2,
    left: 2,
  },
});
